package com.zhihuichongcheng.application.ui.task.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zhihuichongcheng.application.R;
import com.zhihuichongcheng.application.base.BaseActivity;
import com.zhihuichongcheng.application.bean.task.TaskBean;
import com.zhihuichongcheng.application.ui.task.adapter.holder.TaskHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * task adapter Created by LK on 2017/1/5.
 */

public class TaskAdapter extends RecyclerView.Adapter<TaskHolder> {
    private List<TaskBean> dataList = new ArrayList<>();
    private BaseActivity activity;

    public TaskAdapter(BaseActivity activity) {
        this.activity = activity;
    }

    public void reSetData(List<TaskBean> taskBeanList) {
        clear();
        setData(taskBeanList);
    }

    public void clear() {
        this.dataList.clear();
    }

    public void setData(List<TaskBean> data) {
        this.dataList.addAll(data);
    }

    @Override
    public TaskHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.listadapter_task, parent, false);
        return new TaskHolder(itemView, activity);
    }

    @Override
    public void onBindViewHolder(TaskHolder holder, int position) {
        holder.setData(dataList.get(position), position);
    }

    @Override
    public int getItemCount() {
        return this.dataList.size();
    }
}
